app.controller('PageCtrl', ['$scope','$state','$rootScope','$stateParams','$modal', function($scope,$state,$rootScope,$stateParams,$modal) {
	requestServlet("getPageInfo",{id:$stateParams.page},function(rs){
		$scope.page = rs;
	},function(msg){});
	window.addEventListener('message',function(e){
		var data = JSON.parse(e.data)
		if(data.type=="removeLoading"){
			$("#report_"+data.reportId).removeClass('div-loading');
		}
		if(data.type=="setHeight"){
			var webpages = $(".webpage");
			for(var i=0;i<webpages.length;i++){
				webpages.eq(i).css("height",webpages[i].contentWindow.document.body.scrollHeight+"px");
				webpages.eq(i).parent().removeClass('div-loading');
			}
		}
	},false);
	
	
	
	$scope.loadReportIframe=function(portletId,reportId){
		var iframeObj = $("#"+portletId+reportId);
		if(iframeObj.attr("id")!=null){
			if(iframeObj.attr("src")==null){
				var graphSize = Number(iframeObj.attr("graphSize"));
				var height = Number(iframeObj.attr("height"));
				if(height==270||height==0){
					iframeObj.height($(window).height()*(graphSize/100));
				}else{
					iframeObj.height(height);
				}
				iframeObj.attr("src","/suite/app/processtasks/report_detail.jsp?id="+reportId);
			}
		}
	}
	$scope.loadPortlet=function(frame){
		if(frame=="portlet.titleonly"){
			return "panel panel-default";
		}else if(frame=="portlet.default"){
			return "panel panel-info";
		}else if(frame=="portlet.titleframe"){
			return "panel panel-success";
		}else if(frame=="portlet.plain"){
			return "panel panel-default";
		}
	}
	$scope.loadStarkmarksClass=function(inBookmarks){
		if(inBookmarks){
			return "fa fa-star text-muted text-active";
		}else{
			return "fa fa-star text-muted text";
		}
	}
	$scope.loadStarOBookmarksClass=function(inBookmarks){
		if(inBookmarks){
			return "fa fa-star text-warning text";
		}else{
			return "fa fa-star text-warning text-active";
		}
	}
	$scope.toggleBookmarks=function(id,inBookmarks){
		if(inBookmarks){
			requestServlet("removeBookmarks",{id:id},function(rs){
				$state.reload();
			},function(msg){});
		}else{
			requestServlet("addBookmarks",{id:id},function(rs){
				$state.reload();
			},function(msg){});

		}
	}
	
}]);
